package edu.buaa.act.travel.m.adapter;

import java.util.List;

import edu.buaa.act.travel.m.R;
import edu.buaa.act.travel.m.data.SurroundItem;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SurroundsAdapter extends BaseAdapter {

	private List<SurroundItem> mSurroundsList;
	private Activity mActivity;
	
	public SurroundsAdapter(final Activity mActivity,final List<SurroundItem> mSurroundsList) {
		super();
		this.mSurroundsList = mSurroundsList;
		this.mActivity = mActivity;
	}

	@Override
	public int getCount() {
		return mSurroundsList.size();
	}

	@Override
	public Object getItem(int position) {
		return mSurroundsList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null) {
			convertView = mActivity.getLayoutInflater().inflate(R.layout.item_surround_detail, null);
		}
		
		final SurroundItem item = mSurroundsList.get(position);
		final TextView dispName = (TextView) convertView.findViewById(R.id.text_surround_name);
		final TextView dispRank = (TextView) convertView.findViewById(R.id.text_surround_rank);
		final TextView dispSubInfo = (TextView) convertView.findViewById(R.id.text_surround_subInfo);
		
		dispName.setText(item.getName());
		dispRank.setText(String.valueOf(item.getRank()));
		dispSubInfo.setText(item.getAddress());
		
		return convertView;
	}

}
